#include "RotatingIsle.h"

RotatingIsle::RotatingIsle(GameState *gameState, 
							const b2Vec2 &center,
							const float size) : 
							Isle(gameState, size),
							m_center(center)
							{
	deleteProperty("Isle");
	addProperty("RotatingIsle");
	m_texture = gameState->getTextureManager().getTexture("frozenIsle1.png");
	getFixtureDef(0)->friction = 100.0f;
	
	m_theta = 0;
}


void RotatingIsle::firstUpdate(){
	m_originalPos = getPosition();
}


void RotatingIsle::update(double dt){
	
	m_time+=dt;
	m_theta = m_time*0.6f;
	b2Vec2 targetPos;
	b2Vec2 difPos = m_originalPos-m_center;
	targetPos.x = cosf(m_theta) * (difPos.x) - sinf(m_theta) * (difPos.y) + m_center.x;
	targetPos.y = sinf(m_theta) * (difPos.x) + cosf(m_theta) * (difPos.y) + m_center.y;
	//b2Vec2 targetPos(getPosition().x, m_initYPos+cos(m_time+m_initTime));
	m_body->SetLinearVelocity((targetPos-getPosition()));
}




